export async function* bubbleSort(array, compare, swap, set) {
    const n = array.length;
    
    for (let i = 0; i < n - 1; i++) {
        let swapped = false;
        
        for (let j = 0; j < n - i - 1; j++) {
            yield { type: 'compare', indices: [j, j + 1] };
            
            if (await compare(j, j + 1)) {
                yield { type: 'swap', indices: [j, j + 1] };
                await swap(j, j + 1);
                swapped = true;
            }
        }
        
        if (!swapped) break;
    }
    
    yield { type: 'complete' };
}